﻿using Elasticsearch.Net;
using ElasticSearchTest.Model;
using Nest;
using PMS.Search.Domain.Common;
using PMS.Search.Domain.Entities;
using PMS.Search.Elasticsearch;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ElasticSearchTest
{
    public class CommonEsService
    {
        private readonly EsClient _client;
        private readonly EsIndexConfig.Index _index = EsIndexConfig.Instance.ArticleIndex;

        public CommonEsService(EsClient client)
        {
            _client = client;
        }
        public void Test()
        {
            GetIndex("talent");
            //Reindex("article", "articleindex_test");
        }

        public void GetIndex(string alias)
        {
            //full index info
            var indices = _client.GetClient().Indices.Get(alias);
            //alias index info
            var indexAliases = _client.GetClient().Indices.GetAlias(alias);
        }

        public void Reindex(IndexName from, IndexName to, int batchSize = 1000)
        {
            var reindexResponse = _client.GetClient()
                .ReindexOnServer(r => r
                    //.Conflicts(Conflicts.Proceed) //default abort
                    .MaximumDocuments(100)
                    .Source(s => s
                        .Index(from)
                        .Size(batchSize) //size of batch
                    )
                    .Destination(d => d.Index(to))
                    .WaitForCompletion()
                );
        }

    }
}
